//
//  CDVAnalytics.m
//  U9工作台
//
//  Created by 陈伟 on 15/10/8.
//
//

#import <Foundation/Foundation.h>


#import "CDVAnalytics.h"
#import <Cordova/CDVViewController.h>
#import "AppDelegate.h"

@implementation Analytics

- (void)analytics:(CDVInvokedUrlCommand *)command
{
    NSString *flag = [command.arguments objectAtIndex:0];
    NSString *appId = [command.arguments objectAtIndex:1];
    NSString *userName = [NSString new];
    NSString *userPassWord =[NSString new];
    NSString *host=[NSString new];
    NSNumber *port=[NSNumber numberWithInteger:10];
    if([flag isEqualToString:@"clickApp"]==YES){//进入子应用
        
        [MaMobClick  beginLogPageView:appId];
    }
    if([flag isEqualToString:@"goHome"]==YES){//退出子应用
        
        [MaMobClick endLogPageView:appId];
    }
    
    if([flag isEqualToString:@"login"]==YES){
        AppDelegate *de = [UIApplication sharedApplication].delegate;
        
        if (de.userName !=nil) {
            userName = de.userName;
        }
        if (de.userPassWord != nil) {
            userPassWord = de.userPassWord;
        }
        if (de.host != nil) {
                host = de.host;
            }
        if (de.port != nil) {
            port = de.port;
        }
        
        NSMutableDictionary* props = [NSMutableDictionary dictionaryWithCapacity:4];
        [props setObject:userName forKey:@"account"];
        [props setObject:userPassWord forKey:@"password"];
        [props setObject:host forKey:@"address"];
        [props setObject:port forKey:@"port"];
        NSDictionary* res = [NSDictionary dictionaryWithDictionary:props];
        
        CDVPluginResult* pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsDictionary:res];
        [self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId];
        
    }
    
}

@end
